package com.dai.smalldemo.controller;

import com.dai.smalldemo.common.Result;
import com.dai.smalldemo.model.entity.ToEmail;
import com.dai.smalldemo.service.EmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.coyote.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： dkl
 * @date： 2023/12/31
 * @description：
 */
@RestController
@RequestMapping("/email")
@RequiredArgsConstructor
@Api(tags = "邮件服务相关接口")
public class EmailController {
    private EmailService emailService;

    @Autowired
    public EmailController(EmailService emailService) {
        this.emailService = emailService;
    }

    @PostMapping("/send")
    @ApiOperation(value = "发送普通邮件")
    public Result sendEmail(ToEmail toEmail) {
        emailService.sendEmail(toEmail);
        return Result.success("邮件发送成功！");
    }

    @PostMapping("/sendHtml")
    @ApiOperation(value = "发送Html邮件")
    public Result sendHtmlEmail(ToEmail toEmail) throws IOException {
        emailService.sendHtmlEmail(toEmail);
        return Result.success("邮件发送成功!");
    }


}
